Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
php "like" button and .post method

I am implementing a very simple solution for "love it" button. I created a database, an index.php and a survey.js. On the Database site everything is working, the mysqli strings are all fine. When the button is clicked the js increase the value +1 to show on index.php.

Problem is that the $_POST['loveit'] to updated the database is not passing and the database at the end is not updated. Here is the index.php:

<html>
<body>
  <?php
  if ($_POST['loveit']) {
    mysqli_query($con,"UPDATE survey2 SET loveit=loveit+1 WHERE id=1");
  }
  ?>

  <div class="grid">
    <span id="status"></span><br>
    <input type="button" value="<?php echo $loveit; ?>" class="button_loveit" id="loveitBtn" />
  </div>

  <script type="text/javascript" src="../js/jquery.min.js"></script>
  <script type="text/javascript" src="../js/survey.js"></script>
</body>
</html>

and here the survey.js:

$(document).ready(function() {
  $("#loveitBtn").removeAttr("disabled");
  $('#loveitBtn').click(function(e) {
    var val = parseInt($('#loveitBtn').val(), 10);
    $.post("../survey/index.php", {op: "loveitBtn"}, function(data) {
      $("#status").html("Sucessfully!!");
      val = val+1;
      $("#loveitBtn").val(val);
      $("#loveitBtn").attr("disabled", "disabled");
      $("#loveitBtn").css("background-image","url(../survey/like.png)");
    });
  }); 
}

Can you please help me to adjust this little code? Am not an expert, I am just starting out learning and I will appreciate any advice. Many thanks Cheers!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You are not passing 'loveit' as a parameter in the data:

$.post("../survey/index.php", {op: "notgood"},function(data)...

Should look like:

$.post("../survey/index.php", {op: "notgood", loveit: "true" },function(data)...
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda